import java.util.*;
public class NGuessNumber {
    String [] a=new String[4];
    Random random =new Random();
    int [] shuru = new int[4];
    int [] daan = new int[4];
    int [] cd = {0,0};
    public  int [] generateAnswer(){
            for (int i=0;i<a.length;i++) {
            String num = ""+random.nextInt(10);
                while (true) {
                boolean re = true;
                    for (int j = 0; j < a.length; j++) {
                        if (num.equals(a[j])) {
                            re = false;
                            break;
                        }
                    }
                        if (re) {
                            a[i] = num;
                            break;
                        }else {
                            num = ""+random.nextInt(10);
                        }  }

            }
        for (int i=0;i<shuru.length;i++){
            shuru[i]=Integer.parseInt(a[i]);
        }
        return shuru;
    }
    public  int [] getPlayerInput(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入4个0-9的不重复的数字：");
        for (int i = 0; i < daan.length; i++) {
            daan[i]=sc.nextInt();
        }
        return daan;
    }
    public  int [] compareGuessAnswer(){
        for (int i = 0; i < daan.length; i++) {
            for (int j = 0; j < shuru.length; j++) {
                if (shuru[i]==daan[i]){
                    cd[0]+=1;
                }else if (daan[i]==shuru[j]){
                    cd[1]+=1;
                }
            }
        }
        return cd;
    }
    public  Boolean isWin(){
        System.out.println("（A）位置和值全部正确的有"+cd[0]);
        System.out.println("（B）位置不正确但值正确的有"+cd[1]);
        System.out.println("-----有4个值正确则玩家胜利！-----");
        if ((cd[0]+cd[1])>=4){
            return true;
        }
        return false;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i=0;
        while(true) {
            do {
                NGuessNumber nGuessNumber = new NGuessNumber();
                nGuessNumber.generateAnswer();
                nGuessNumber.getPlayerInput();
                nGuessNumber.compareGuessAnswer();
                if (nGuessNumber.isWin()) {
                    System.out.println("胜利");
                } else {
                    System.out.println("失败");
                }
                i++;
            } while (i == 1);
            System.out.println("结束游戏0,再来一局1");
            int clm = sc.nextInt();
            if (clm == 0) {
                break;
            }
        }
    }
}
